import { IToolTipItem } from "../../../../../com/mui/manager/IToolTipItem";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { NpcEffectRule } from "../../../rules/NpcEffectRule";
import { ENpcEffect } from "../../../../../Message/Public/ENpcEffect";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { NPCInfo } from "../../../model/NPCInfo";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { ToolTipsManager } from "../../../../../com/mui/manager/ToolTipsManager";
//class NPCItem
    
    export  class NPCItem /* flash.display.Sprite */ implements IToolTipItem
    {
        constructor()
        {
            
            this._itemSprite = new Object /* flash.display.Sprite */();
            addChild(this._itemSprite);
            this._bitmap = new Object /* flash.display.Bitmap */();
            this._itemSprite.addChild(this._bitmap);
            this._itemSprite.buttonMode = true;
            this._nameLabel = new Object /* flash.text.TextField */();
            this._nameLabel.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._nameLabel.selectable = false;
            this._nameLabel.defaultTextFormat = new GTextFormat(null, 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._nameLabel.filters = [FilterConst.nameGlowFilter];
            this._itemSprite.addChild(this._nameLabel);
            this.mouseEnabled = false;
            this.mouseChildren = true;
            addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            return;
        }

        protected onMapUIResLoadedHandler(): void
        {
            if (this._data) 
            {
                if (!GameMapUtil.curMapState.isCrossCountry && NpcEffectRule.hasNpcEffectByTnpc(this._data.tnpc.effectDes, ENpcEffect._ENpcEffectCopy129) || GameMapUtil.curMapState.isCrossCountry && NpcEffectRule.hasNpcEffectByTnpc(this._data.tnpc.effectCross, ENpcEffect._ENpcEffectCopy129)) 
                {
                    this._bitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.MapUIPass);
                    this._nameLabel.htmlText = HTMLUtil.addColor(this._data.snpc.name + Language.getString(20632), "#ffffff");
                    this._nameLabel.y = -this._bitmap.height;
                }
                else 
                {
                    this._bitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.MapUINPCPosition);
                    this._nameLabel.htmlText = HTMLUtil.addColor(this._data.snpc.name, "#ffff00");
                    this._nameLabel.y = -this._bitmap.height + 8;
                }
            }
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new DataEvent(EventName.NpcItemClick, this._data));
            return;
        }

        public set data(arg1: NPCInfo)
        {
            if (arg1 == null) 
            {
                return;
            }
            this._data = arg1;
            if (this._data.snpc && this._data.tnpc) 
            {
                LoaderHelp.addResCallBack(ResFileConst.mapUI, this.onMapUIResLoadedHandler);
                if (!(this._data.tnpc.career == null) && !(this._data.tnpc.career == "")) 
                {
                    this.toolTipData = HTMLUtil.addColor(this._data.tnpc.career + "-" + this._data.tnpc.name, "#ffffff");
                }
                else 
                {
                    this.toolTipData = HTMLUtil.addColor(this._data.tnpc.name, "#ffffff");
                }
                this._nameLabel.x = (this._bitmap.width - this._nameLabel.textWidth) / 2;
            }
            return;
        }

        public get data(): NPCInfo
        {
            return this._data;
        }

        public dispose(): void
        {
            this.toolTipData = null;
            this._data = null;
            return;
        }

        public /* override */ get height(): number
        {
            if (this._bitmap.bitmapData) 
            {
                return this._bitmap.height;
            }
            return 22;
        }

        public /* override */ get width(): number
        {
            if (this._bitmap.bitmapData) 
            {
                return this._bitmap.width;
            }
            return 10;
        }

        public get toolTipData()
        {
            return this._tooltipData;
        }

        public set toolTipData(arg1)
        {
            if (arg1 == null || arg1 == "") 
            {
                ToolTipsManager.unregister(this);
            }
            else 
            {
                ToolTipsManager.register(this);
            }
            this._tooltipData = arg1;
            return;
        }

        /* internal */ /* var */_data: NPCInfo;

        /* internal */ /* var */_itemSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_tooltipData;
    }
